﻿$(function () {
    $("#btn_Login").click(function () {
        if (!loginValidate()) {
            return false;
        }
        $("#desk").html("· 正在验证登录...");

        var clientJson = {
            LoginID: $("#txt_LoginID").val(),
            Password: $("#txt_Password").val(),
            SaveAccount: $("#chk_RememberMe").val() == "on" ? true : false,
            Message: "",
            IsSuccess: false,
            CaptchaImageText: $("#tbxCaptcha").val()
        };
        // alert($.toJSON(clientJson));
        CallServerMethod($.toJSON(clientJson), null);
        return false;
    });
    if ($("#txt_LoginID").val().length == 0)
        $("#txt_LoginID").focus();
    else
        $("#txt_Password").focus();

    if (window.top.location == self.location)
        window.top.location = "Main.aspx";
});
var k = "____NewTeaching";
function Success(args, context) {
    try {
        var result = $.parseJSON(args);
        if (result.IsSuccess) {
            //..登录成功..

            //设置Cookie
            if (result.SaveAccount)
                Set(k, result.LoginID);
            else
                Clear(k);
            //禁用其他按钮..
            $("input").attr("disabled", true);
            $("#btn_Close").attr("disabled", true);
            $("#desk").html(result.Message + "页面正在跳转...");
            //parent.tipsClose();
            setTimeout('window.top.location.reload();', 1200);
        }
        else {
            //提示错误,.. 
            $("#desk").html(result.Message);
        }
    } catch (e) {
        $("#desk").html(e.Message);
    }

}
function Error(args, context)
{ $("#desk").html(args); }


function Set(key, value) {
    $.cookie(key, value, { expires: 14 });
}
function Clear(key) {
    $.cookie(key, null, { expires: -1 });
}

///登录验证
function loginValidate() {
    var isValidated = false;
    if ($.trim($("#txt_LoginID").val()).length == 0) {
        setMsg("· 请输入账号<span class=\"Tips\">（如果是学生，请使用您的学号登录）</span>");
        $("#txt_LoginID").focus();
    }
    else if ($.trim($("#txt_Password").val()).length == 0) {
        setMsg("· 请输入密码 ");
        $("#txt_Password").focus();
    }
    //    else if ($.trim($("#tbxCaptcha").val()).length == 0) {
    //        alert("请输入验证码."); $("#tbxCaptcha").focus();
    //    }
    else
    { isValidated = true; }
    return isValidated;
}

function setMsg(msg) {
    $("#desk").html(msg);
}